package com.zone.mybatis.executor.statement;

import com.zone.mybatis.executor.resultset.ResultSetHandler;
import com.zone.mybatis.mapping.BoundSql;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

/**
 * @author: zongzi
 * @description: TODO
 * @date: 2024/1/1
 */
public class SimpleStatementHandler extends BaseStatementHandler {

    private BoundSql boundSql;
    private ResultSetHandler resultSetHandler;

    public SimpleStatementHandler(BoundSql boundSql, ResultSetHandler resultSetHandler) {
        this.boundSql = boundSql;
        this.resultSetHandler = resultSetHandler;
    }

    @Override
    public Statement instantiateStatement(Connection connection) throws SQLException {
        return connection.createStatement();
    }

    @Override
    public void parameterize(Statement statement) throws SQLException {

    }

    @Override
    public <E> List<E> query(Statement statement) throws SQLException {
        String sql = boundSql.getSql();
        statement.execute(sql);
        return resultSetHandler.handleResultSet(statement);
    }
}
